package com.example.g32.Req

import com.example.base.http.ApiServer
import com.example.base.mvi.BaseViewModel
import com.example.base.room.UserDao
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

@HiltViewModel
class UserViewModel @Inject constructor(val apiServer: ApiServer, val userDao: UserDao): BaseViewModel<UserIntent>() {
    override fun handlerIntent(it: UserIntent) {
        when(it){
            is UserIntent.register->{
                httpRequest(apiServer.Req(it.pass, it.name))
            }

            is UserIntent.registerRoom->{
                roomRequest(flow { emit(userDao.register(it.entity)) })
            }
        }
    }
}